/*
 * @brief Sensor packet (implementation file)
 *
 * @note
 * Copyright(C) NXP Semiconductors, 2015
 * All rights reserved.
 *
 * @par
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * LPC products.  This software is supplied "AS IS" without any warranties of
 * any kind, and NXP Semiconductors and its licensor disclaim any and
 * all warranties, express or implied, including all implied warranties of
 * merchantability, fitness for a particular purpose and non-infringement of
 * intellectual property rights.  NXP Semiconductors assumes no responsibility
 * or liability for the use of the software, conveys no license or rights under any
 * patent, copyright, mask work right, or any other intellectual property rights in
 * or to any products. NXP Semiconductors reserves the right to make changes
 * in the software without notification. NXP Semiconductors also makes no
 * representation or warranty that such application will be suitable for the
 * specified use without further testing or modification.
 *
 * @par
 * Permission to use, copy, modify, and distribute this software and its
 * documentation is hereby granted, under NXP Semiconductors' and its
 * licensor's relevant copyrights in the software, without fee, provided that it
 * is used in conjunction with NXP Semiconductors microcontrollers.  This
 * copyright, permission, and disclaimer notice must appear in all copies of
 * this code.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

#include "trace.h"

#include "hostif_protocol.h"
#include "sensor_pkt.h"

//------------------------------------------------------------------------------
// This structure must match the sensor IDs in hostif_protocol.h exactly.
// even though the BSXLite library only supports a subset of the sensors.
// Here is the exact list:
//
// - LPCSH_SENSOR_ID_ACCELEROMETER
// - LPCSH_SENSOR_ID_ACCELEROMETER_UNCALIBRATED
// - LPCSH_SENSOR_ID_MAGNETIC_FIELD
// - LPCSH_SENSOR_ID_MAGNETIC_FIELD_UNCALIBRATED
// - LPCSH_SENSOR_ID_GYROSCOPE
// - LPCSH_SENSOR_ID_GYROSCOPE_UNCALIBRATED
// - LPCSH_SENSOR_ID_LIGHT
// - LPCSH_SENSOR_ID_PRESSURE (includes temperature)
// - LPCSH_SENSOR_ID_PROXIMITY
// - LPCSH_SENSOR_ID_ORIENTATION (deprecated)
// - LPCSH_SENSOR_ID_ROTATION_VECTOR
//
//	All other sensors should be marked as un-supported.
//------------------------------------------------------------------------------
static const uint32_t m_sensorDataLen[LPCSH_SENSOR_ID_COUNT] =
{
	sizeof(struct lpcsh_motion_sensor_node),					// 00: LPCSH_SENSOR_ID_ACCELEROMETER
	sizeof(struct lpcsh_motion_sensor_node),					// 01: LPCSH_SENSOR_ID_ACCELEROMETER_UNCALIBRATED
	sizeof(struct lpcsh_motion_sensor_node),					// 02: LPCSH_SENSOR_ID_MAGNETIC_FIELD
	sizeof(struct lpcsh_motion_sensor_node),					// 03: LPCSH_SENSOR_ID_MAGNETIC_FIELD_UNCALIBRATED
	sizeof(struct lpcsh_motion_sensor_node),					// 04: LPCSH_SENSOR_ID_GYROSCOPE
	sizeof(struct lpcsh_motion_sensor_node),					// 05: LPCSH_SENSOR_ID_GYROSCOPE_UNCALIBRATED
	sizeof(struct lpcsh_motion_sensor_node),					// 06: LPCSH_SENSOR_ID_LIGHT
	sizeof(struct lpcsh_motion_sensor_node),					// 07: LPCSH_SENSOR_ID_PRESSURE
	sizeof(struct lpcsh_motion_sensor_node),					// 08: LPCSH_SENSOR_ID_PROXIMITY
	sizeof(struct lpcsh_motion_sensor_node),					// 09: LPCSH_SENSOR_ID_RELATIVE_HUMIDITY
	sizeof(struct lpcsh_motion_sensor_node),					// 10: LPCSH_SENSOR_ID_AMBIENT_TEMPERATURE
	sizeof(struct lpcsh_motion_sensor_node),					// 11: LPCSH_SENSOR_ID_GRAVITY
	sizeof(struct lpcsh_motion_sensor_node),					// 12: LPCSH_SENSOR_ID_LINEAR_ACCELERATION
	sizeof(struct lpcsh_orientation_node),						// 13: LPCSH_SENSOR_ID_ORIENTATION
	sizeof(struct lpcsh_quaternion_node),						// 14: LPCSH_SENSOR_ID_ROTATION_VECTOR
	sizeof(struct lpcsh_quaternion_node),						// 15: LPCSH_SENSOR_ID_GEOMAGNETIC_ROTATION_VECTOR
	sizeof(struct lpcsh_quaternion_node),						// 16: LPCSH_SENSOR_ID_GAME_ROTATION_VECTOR
	sizeof(struct lpcsh_step_sensor_node),						// 17: LPCSH_SENSOR_ID_STEP_DETECTOR
	sizeof(struct lpcsh_step_sensor_node),						// 18: LPCSH_SENSOR_ID_STEP_COUNTER
	sizeof(struct lpcsh_significant_motion_node),				// 19: LPCSH_SENSOR_ID_SIGNIFICANT_MOTION
	sizeof(struct lpcsh_activity_classification_state_node),	// 20: LPCSH_SENSOR_ID_ACTIVITY_CLASSIFICATION_STATE
	0,															// 21: LPCSH_SENSOR_ID_AUG_REALITY_COMPASS
	sizeof(struct lpcsh_tap_sensor_node),						// 22: LPCSH_SENSOR_ID_TAP_DETECTOR
	sizeof(struct lpcsh_shake_sensor_node),						// 23: LPCSH_SENSOR_ID_SHAKE_DETECTOR
	0,															// 24: LPCSH_SENSOR_ID_STEP_SEGMENT_DETECTOR
	sizeof(struct ShVoiceTriggerWriteUserDataCommand_t),		// 25: LPCSH_SENSOR_ID_VOICE_TRIGGER
	sizeof(struct lpcsh_ir_blaster_rx_node),					// 26: LPCSH_SENSOR_ID_IR_BLASTER_RX_PACKET
	sizeof(struct lpcsh_ir_blaster_status_node),				// 27: LPCSH_SENSOR_ID_IR_BLASTER_STATUS
	sizeof(struct lpcsh_meta_sensor_flush_done_node)			// 28: LPCSH_SENSOR_ID_META_SENSOR_FLUSH_DONE
};

//------------------------------------------------------------------------------
//	get header length
//
//	This function returns the length of a packet header
//------------------------------------------------------------------------------
uint32_t get_hdr_len(void)
{
	return sizeof(struct lpcsh_sensor_node_header);
}

//------------------------------------------------------------------------------
//	get data length
//
//	This function returns the length of a data packet
//------------------------------------------------------------------------------
uint32_t get_data_len(uint32_t id)
{
	if (id > LPCSH_SENSOR_ID_COUNT) {
		trace(TRACE_INFO,"packet ID out of range: %d\n",id);
		exit(1);
	}

	return  m_sensorDataLen[id];
}

//
//	End: sensor_pkt.c
//
